package com.ruoyi.framework.listener;


import com.ruoyi.common.core.domain.entity.SysLogininfor;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.event.LogininforEvent;
import com.ruoyi.system.service.ISysLogininforService;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author cql
 */
@Component
public class LogininforListener implements ApplicationListener<LogininforEvent> {

    @Async
    @Override
    public void onApplicationEvent(LogininforEvent logininforEvent) {
        SysLogininfor logininfor = logininforEvent.getLogininfor();
        System.out.println("LogininforListener:" + Thread.currentThread().getName());
        logininfor.setLoginTime(new Date());
        SpringUtils.getBean(ISysLogininforService.class).insertLogininfor(logininfor);
    }
}
